package com.igeekhome.controller.api;

import com.github.pagehelper.PageInfo;
import com.igeekhome.dto.OrderNumberListDto;
import com.igeekhome.mapper.WWaybillRuleMapper;
import com.igeekhome.pojo.DOrderNumberList;
import com.igeekhome.pojo.WWaybillRule;
import com.igeekhome.pojo.WWaybillRuleExample;
import com.igeekhome.service.IOrderNumberListService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/orderNumberList")
public class OrderNumberListControllerApi {

    @Autowired
    private IOrderNumberListService orderNumberListService;

    @Autowired
    private WWaybillRuleMapper wWaybillRuleMapper;



    @RequestMapping("/list")
    public TableResultBean waybillRuleList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit,DOrderNumberList orderNumberList,String searchTime){
        PageInfo<OrderNumberListDto> pageInfo = orderNumberListService.select(page, limit,orderNumberList,searchTime);
        Long total = pageInfo.getTotal();
        return new TableResultBean(0,"成功",total,pageInfo.getList());
    }

    @RequestMapping("/delete")
    public ResultBean delete(String idsStr){
        return orderNumberListService.deleteMethod(idsStr);
    }

    @RequestMapping("/add")
    public ResultBean add(DOrderNumberList orderNumberList){
        Integer flag = orderNumberListService.saveMethod(orderNumberList);
        if(flag==1){
            return ResultBean.success();
        }else{
            return ResultBean.fail("失败");
        }
    }

    @RequestMapping("/update")
    public ResultBean update(DOrderNumberList orderNumberList){
        orderNumberListService.updateMethod(orderNumberList);
        return ResultBean.success();
    }

    @RequestMapping("/changeUseStatus")
    public ResultBean changeUseStatus(Integer id,Integer parentNetworkId){
        DOrderNumberList orderNumberList = new DOrderNumberList();
        orderNumberList.setParentNetworkId(parentNetworkId);
        orderNumberList.setId(id);
        orderNumberList.setServiceCondition(1);
        orderNumberListService.changeUse(orderNumberList);
        return ResultBean.success();

    }

}
